package com.tinyseed.emcp.api.basicdata.repository;

import com.tinyseed.emcp.api.basicdata.domain.Enterprise;
import com.tinyseed.emcp.api.dashboard.query.TreeQuickQuery;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;
import java.util.Map;

public interface EnterpriseRepository extends JpaRepository<Enterprise, Long>, JpaSpecificationExecutor<Enterprise> {

    Enterprise findTbCompanyEntitiesByEnterpriseName(String companyName);

    Page<Enterprise> findAllByEnterpriseName(String EnterpriseName, Pageable pageable);

    Enterprise findByEnterpriseName(String enterpriseName);

    @Query(value = "select id,enterprise_name,organize_id from tb_enterprise", nativeQuery = true)
    List<Map<String, Object>> findEnterprises();

    @Query(value = "select * from tb_enterprise m where m.id = :id", nativeQuery = true)
    Enterprise getById(@Param("id") Long id);

    @Query(value = "select new com.tinyseed.emcp.api.dashboard.query.TreeQuickQuery(e.id,e.enterpriseName,e.organizeId) from Enterprise e")
    List<TreeQuickQuery> findEnterpriseTree();


}
